#ifndef __SPL06_H
#define __SPL06_H


#include "main.h"
#include "myiic.h"
#include <math.h>



#define SPL_CLK_ENABLE			__HAL_RCC_GPIOB_CLK_ENABLE()		

#define SPL_ADDRESS					0x76



//your own settings
//see the table in the datasheet
//#define KT							524288.0	
//#define KP							253952.0
#define KT							524288.0		
#define KP							1572864.0


//register map
//pressure data
#define SPL_PRS_B2					0x00
#define SPL_PRS_B1					0x01
#define SPL_PRS_B0					0x02
//temperature data
#define SPL_TMP_B2					0x03
#define SPL_TMP_B1					0x04
#define SPL_TMP_B0					0x05
//Config
#define SPL_PRS_CFG					0x06
#define SPL_TMP_CFG					0x07
#define SPL_MEAS_CFG				0x08
#define SPL_CFG_REG					0x09
#define SPL_INT_STS					0x0A
#define SPL_FIFO_STS				0x0B
#define SPL_RESET_REG				0x0C
//ID
#define SPL_ID_REG					0x0D


//Station
#define LOWPOWER						1
#define INDOOR							2
#define SPORTS							3


//Calibration Coefficients
#define COEF_C0						0x10
#define COEF_C0_C1				0x11
#define COEF_C1						0x12
#define COEF_C00_H				0x13
#define COEF_C00_L				0x14
#define COEF_C00_C10			0x15
#define COEF_C10_M				0x16
#define COEF_C10_L				0x17
#define COEF_C01_H				0x18
#define COEF_C01_L				0x19
#define COEF_C11_H				0x1A
#define COEF_C11_L				0x1B
#define COEF_C20_H				0x1C
#define COEF_C20_L				0x1D
#define COEF_C21_H				0x1E
#define COEF_C21_L				0x1F
#define COEF_C30_H				0x20
#define COEF_C30_L				0x21


extern iic_bus_struct spl06_iic_struct;


u8 SPL06_Read_Byte(u8 reg);

void SPL06_Set_Mode(u8 mode);
u8 SPL06_ReadID(void);

u8 SPL06_Init(void);

int32_t get_press(void);
int32_t get_temp(void);

int16_t get_c0(void);
int16_t get_c1(void);
int32_t get_c00(void);
int32_t get_c10(void);
int16_t get_c01(void);
int16_t get_c11(void);
int16_t get_c20(void);
int16_t get_c21(void);
int16_t get_c30(void);


float Altitude_Calculate(void);
float Pressure_Calculate(void);
float Temperature_Calculate(void);

#endif
